jQuery(function(){
	
	loadMenu();
	loadTree();
});

/**
 * 加载菜单
 */
function loadMenu(){
	
	
}

/**
 * 加载树
 */
function loadTree(){
	
	var treeNode = $("#showTree");
	if(treeNode.size() > 0){
		
		var setting = {
			async: {
				enable: true,
				url:"getHierarchy.action",
				autoParam:["id", "name", "level"],
				otherParam:{"operationFlag":"1"}
			}
		};

		function filter(treeId, parentNode, childNodes) {
			if (!childNodes) return null;
			for (var i=0, l=childNodes.length; i<l; i++) {
				childNodes[i].name = childNodes[i].name.replace(/\.n/g, '.');
			}
			return childNodes;
		}

		treeObj = $.fn.zTree.init(treeNode, setting);
	}
}

/**
 * 新增
 */
function add(){
	
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length == 0){
		
		window.location = "add.action";
	}else{
		
		window.location = "add.action?parent_id=" + nodes[0].id;
	}
}

/**
 * 编辑
 */
function edit(){
	
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length == 0){
		
		JM.alert('请至少选择一个节点');
	}else{
		
		window.location = "edit.action?id=" + nodes[0].id;
	}
}

/**
 * 删除
 */
function deleteNode(){
	
	var nodes = treeObj.getSelectedNodes();
	if(nodes.length == 0){
		
		JM.alert('请至少选择一个节点');
	}else{
		
		window.location = "delete.action?id=" + nodes[0].id;
	}
}